/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.Dictionary;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
/**
 *
 * @author BunEri0463
 */

public class Help {
    
    public static void helpmenu(JFrame frame)
    {
        
        
        
        
        final JFrame frames=new JFrame("Help Menu");
        JRootPane rootPane = frames.getRootPane();
        String def;
        
        
        //Definition area
        final JTextArea area=new JTextArea(10,30);
        area.setEditable(false);
        area.setLineWrap(true);
        area.setWrapStyleWord(true);
        final JScrollPane scroll=new JScrollPane(area);
        area.setText("Click any of the buttons to find out what they do.");
        
        
        
        //Search Box
        final JLabel word=new JLabel("Word: ");
        final JTextField wod=new JTextField(10);
        wod.setText("Input Word");
        final JPanel search=new JPanel();
        
        //actionlistener/key binding class for about menu
        class info extends AbstractAction
        {
            public info(String str)
            {
             super(str);
            }
            public void actionPerformed(ActionEvent e)
            {
              area.setText("Menu with developer information. Press Alt+a to access or click on the button.");  
            }            
        }
        AbstractAction aboutcrack=new info("About");
        final JButton about=new JButton(aboutcrack);
        search.add(about);
        rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_A , InputEvent.ALT_DOWN_MASK), "aboutclick");
        rootPane.getActionMap().put("aboutclick",aboutcrack);
        
        //add search box to bar
        search.add(word);
        search.add(wod);
        
        
        //actionlistener/keybinding class for define
        class actions extends AbstractAction
        {
            public actions(String str)
            {
             super(str);
            }
          public void actionPerformed(ActionEvent e)
            {
              
                    area.setText("Click to define the word. Press Enter to define or click on the button.");
            }
        }
        AbstractAction define=new actions("Define");
        final JButton find=new JButton(define);
        search.add(find);
        rootPane.setDefaultButton(find);
        
        
        //copy definition to Writer
        class copy extends AbstractAction
        {
            public copy (String str,Icon icn)
            {
             //super(str,icn);
             super(str);
            }
          public void actionPerformed(ActionEvent e)
          {
               
              area.setText("Copy definition to clipboard. You can then paste it into anything you want. Press Ctrl+c to copy to clipboard or press the button.");
              //AddText.main(area.getText());
          }            
        }
        Icon cpimg=new ImageIcon("images/copy.png");
        AbstractAction addtodoc=new copy("Copy",cpimg);
        final JButton addto=new JButton(addtodoc);
        //addto.setMargin(new Insets(0,0,0,0));
        search.add(addto);
        rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_C , InputEvent.CTRL_DOWN_MASK), "copy");
        rootPane.getActionMap().put("copy",addtodoc);
        
      
      
      
     //init of window
      frames.add(search, BorderLayout.NORTH);
      frames.add(scroll);
      frames.setSize(425, 300);
      frames.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frames.setVisible(true);
      
     //position of window
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension window=frame.getSize();
      int x = (screenSize.width/2);
      int y = (screenSize.height/2);
      frames.setLocation(x, y);
    }
}
